package vip.specimen.system.datasource.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * *@Author: 余浪人
 * *@Date：2021/2/22 14:46
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
@Getter
@Setter
@Entity
@Table(name = "system_user")
public class SystemUserEntity extends BaseEntity {
    @Column(length = 16)
    @ApiModelProperty(value = "用户名")
    private String username;
    @JsonIgnore
    @Column(length = 32)
    @ApiModelProperty(value = "密码")
    private String password;
    @Column(length = 128)
    @ApiModelProperty(value = "昵称")
    private String name;
    @Column(length = 64)
    @ApiModelProperty(value = "email")
    private String email;
    @Column(length = 15)
    @ApiModelProperty(value = "联系电话")
    private String phone;
    @Column(length = 3)
    @ApiModelProperty(value = "年龄", dataType = "int")
    private int age;
    @Column(length = 1)
    @ApiModelProperty(value = "性别", dataType = "Integer")
    private Integer gender = 0; // 0：保密    2：女      1：男
    @ApiModelProperty(value = "角色", dataType = "List")
    @ManyToMany(fetch = FetchType.EAGER)// 立即从数据库中进行加载数据
    @JoinTable(name = "system_user_role", joinColumns = @JoinColumn(name = "system_user_uuid"), inverseJoinColumns = @JoinColumn(name = "system_role_uuid"))
    private List<SystemRoleEntity> systemRole;
    @JsonIgnore
    @Column(length = 16)
    @ApiModelProperty(value = "盐值")
    private String salt;
    @ApiModelProperty(value = "是否管理员")
    private boolean admin = Boolean.FALSE;
    @ApiModelProperty(value = "头像")
    private String portrait;
    @ApiModelProperty(value = "登录次数", dataType = "long")
    private long loginDegree;
    @ApiModelProperty(value = "登录IP")
    private String loginIp;
    @ApiModelProperty(value = "登录时间", dataType = "Date")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date loginEndDate;

    public SystemUserEntity() {
    }

    public SystemUserEntity(String username, String password, String name, String email, String phone, int age, Integer gender, List<SystemRoleEntity> systemRole, String salt, boolean admin, String portrait) {
        this.username = username;
        this.password = password;
        this.name = name;
        this.email = email;
        this.phone = phone;
        this.age = age;
        this.gender = gender;
        this.systemRole = systemRole;
        this.salt = salt;
        this.admin = admin;
        this.portrait = portrait;
    }

    @Override
    public String toString() {
        return "SystemUserEntity{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", name='" + name + '\'' +
                ", email='" + email + '\'' +
                ", phone='" + phone + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                ", systemRole=" + systemRole +
                ", salt='" + salt + '\'' +
                ", admin=" + admin +
                ", id=" + id +
                ", uuid=" + uuid +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}
